<?php

namespace app\common\model;

use think\Model;

class Admin extends Model
{
    // 表名
    protected $name = 'admin';

    //分公司查询上级区域公司
    public static function region($region_id)
    {
        $admin = new self;
        $address = explode(',', $region_id);
        $pid = Area::where('id', $address[0])->value('pid');
        return $admin->where("FIND_IN_SET({$pid},region_id)")->find();
    }
    public function city()
    {
        return $this->belongsTo(Admin::class, 'pid', 'id', [], 'left')->setEagerlyType(0);
    }
}
